import json
import cv2
root_dir = './val_cut/'
data = []
target = []

with open('character_val.json','r',encoding='UTF-8') as f:
    chara_json=json.load(f)
    f.close

for x in chara_json:
    print(x)
    img = cv2.imread(root_dir+x)
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    new_img = cv2.resize(gray, (32,32))
    target.append(chara_json[x])
    data_line = []
    for line in list(new_img):
        for item in list(line):
            data_line.append(item)
    data.append(data_line)

with open("val.csv",mode="a") as f:
    for i in range(len(data)):
        string = ''
        for item in data[i]:
            string += str(item) + ","
        string += target[i] + '\n'
        f.write(string)

